﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;

using ClientLib;

namespace JigsawAdmin
{
    public partial class Home : Form
    {
        ClientUtil _cutil;
        JsvcEnc.EncSoapXml xmlsvc;

        public delegate void HomeUpdatedEventHandler(object sender, HomeUpdateEventArgs e);
        public event HomeUpdatedEventHandler HomeUpdated;

        public Home(ClientUtil cUtil)
        {
            InitializeComponent();

            _cutil = cUtil;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Home_Shown(object sender, EventArgs e)
        {
            try
            {
                // trigger main form resize
                HomeUpdated(this, new HomeUpdateEventArgs());

                // set URL to Jigsaw homepage
                string projecturl = ConfigurationManager.AppSettings["HOMEPAGE"].ToString();
                homeWebBrowser.Navigate(projecturl);

                // save test event
                xmlsvc = new JsvcEnc.EncSoapXml();
                EncryptUtil eutil = new EncryptUtil();
                Dictionary<string, string> paramList = new Dictionary<string, string>();
                paramList.Add("AppName", "JigsawAdmin");
                paramList.Add("AppEventName", "Home Form");
                string encryptedinput = _cutil.BuildMessageXML("Events.Clickstream.Base", paramList, true);
                string results = xmlsvc.Controller(_cutil.EncSymmKey, encryptedinput);
                _cutil.ParseResponseMessage(eutil.DecryptString2(results, _cutil.SymmKey));
            }
            catch (Exception ex)
            {
                ErrorUtil eutil = new ErrorUtil();
                eutil.LogException(_cutil.UserID, "Home InitializeData", "", ex);
            }
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public class HomeUpdateEventArgs : System.EventArgs
    {
        public HomeUpdateEventArgs()
        {

        }
    }
}
